package com.olah.common.entity.po.ws.dto.core;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * websocket 协议的响应, 需要指明响应类型, 由哪个方法处理, 响应数据以及附带消息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WebSocketResponse {

    // 响应类型
    private WebSocketResponseType type;

    // 响应数据
    private String data;

    // 附带消息
    private String msg;

    // 处理方法名
    private String handler;

    public static WebSocketResponse tip(String msg) {
        return new WebSocketResponse(WebSocketResponseType.TIP, null, msg, "tips");
    }

    public static WebSocketResponse system(String data, String msg, String handler) {
        return new WebSocketResponse(WebSocketResponseType.SYSTEM, data, msg, handler);
    }

    public static WebSocketResponse _private(String data, String msg, String handler) {
        return new WebSocketResponse(WebSocketResponseType.PRIVATE, data, msg, handler);
    }

    public String toString() {
        return JSON.toJSONString(this);
    }

}
